﻿using Emoney.UserTraining.BLL;
using Emoney.UserTraining.Cache;
using Emoney.UserTraining.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Emoney.UserTraining.Web
{
    public class Traincom
    {
        public static int GetOrderLst(string netid, string uname)
        {
            Training_MeetingUserBLL bll = new Training_MeetingUserBLL();
            Training_MeetingUser c = new Training_MeetingUser();
            c.netid = netid;
            c.username = uname;

            List<Training_MeetingUser> lst = bll.GetLstOrderUser(c);
            return lst.Count;
        }

        public string Getpid(string uid)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            var c = GetUser(ref dic, uid);
            return dic.ContainsKey("pid") ? dic["pid"] : "";
        }
        Emoney.UserTraining.Web.GetUserName.UserLoginInfo GetUser(ref Dictionary<string, string> dic, string uid)
        {
            string querystirng = "";
            string memkey = "UserTrainUrlSSO_" + uid;
            News2CacheTools cache = new News2CacheTools();
            object obj = cache.Get<object>(memkey);
            if (obj != null)
            {
                querystirng = (string)obj;
            }
            if (!string.IsNullOrEmpty(querystirng))
            {
                string[] arr = querystirng.Split('&');
                foreach (var c in arr)
                {
                    var a2 = c.Split('=');
                    var key = a2.Length > 0 ? a2[0] : "";
                    var value = a2.Length > 1 ? a2[1] : "";
                    if (!dic.ContainsKey(key))
                    {
                        dic.Add(key, value);
                    }
                }
                Emoney.UserTraining.Web.GetUserName.access access = new Emoney.UserTraining.Web.GetUserName.access();
                var user = access.GetUserInfo(querystirng, "127.0.0.1", 0);
                if (!string.IsNullOrEmpty(user.UserName))
                {
                    return user;
                }
                else
                {
                    return new Emoney.UserTraining.Web.GetUserName.UserLoginInfo();
                }
            }
            else
            {
                return new Emoney.UserTraining.Web.GetUserName.UserLoginInfo();
            }
        }
    }
}